package com.bookstore.back.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bookstore.back.entity.NewsCategory;
import com.bookstore.back.mapper.NewsCategoryMapper;
import com.bookstore.back.service.NewsCategoryService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 新闻分类服务实现类
 * 
 * @author 程序猿_Ti
 * @since 2025-07-23
 */
@Service
public class NewsCategoryServiceImpl extends ServiceImpl<NewsCategoryMapper, NewsCategory> 
        implements NewsCategoryService {

    @Override
    public List<NewsCategory> getEnabledCategories() {
        QueryWrapper<NewsCategory> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", 1)
                   .orderByAsc("sort_order")
                   .orderByAsc("id");
        return this.list(queryWrapper);
    }

    @Override
    public List<NewsCategory> getCategoriesByStatus(Integer status) {
        QueryWrapper<NewsCategory> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", status)
                   .orderByAsc("sort_order")
                   .orderByAsc("id");
        return this.list(queryWrapper);
    }

    @Override
    public boolean isNameExists(String name) {
        QueryWrapper<NewsCategory> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name", name);
        return this.count(queryWrapper) > 0;
    }
}
